package com.yc.healthy.controller;


import com.yc.healthy.entity.Food;
import com.yc.healthy.entity.Result;
import com.yc.healthy.mapper.FoodMapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyl
 * @since 2023-03-08
 */
@Controller
@RequestMapping("/healthy/food")
public class FoodController {

    @Resource
    FoodMapper foodMapper;

    @PostMapping("querybyftype")
    @ResponseBody
    public Result queryBytype(@RequestParam("type") String type){
        List<Food> foods = foodMapper.SelectBytype(type);
        System.out.println(foods);
        if (foods.isEmpty()){
            return new Result(0,"查无数据",null);
        }else {
            return new Result(1,"查询成功",foods);
        }

    }

    @PostMapping("querybyId")
    @ResponseBody
    public Result queryById(@RequestParam("id") int id){
        Food food = foodMapper.QueryById(id);
        if ("".equals(food) || food == null){
            return new Result(0,"查无数据",null);
        }else {
            return new Result(1,"查询成功",food);
        }

    }
}

